from selenium.webdriver import ActionChains
from hyrobot.common import STEP, CHECK_POINT, INFO
from create_table_super_num import *
import pyautogui
import pytest
import time
import json
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from pymysql_connect import *
from lib.webui_local_mysql import *

class c73261:
    name = '核对产品管理员创建的信息查看到的信息与普通用户的信息-c73261'  # 测试用例名字


    # 测试用例步骤
    def teststeps(self):


        STEP(2, "核对普通用户查看产品列表数量与产品管理员查看产品列表数量是否一致")
        db = connect()
        # 使用cursor()方法获取操作游标

        cursor_product_list = db.cursor()
        product_list_sql = "SELECT count(id) as display_num FROM test_kylin_web.product_list_for_user;"
        try:
            # 执行SQL语句
            cursor_product_list.execute(product_list_sql)
            # 获取所有记录列表
            product_list_result = cursor_product_list.fetchall()
            for row in product_list_result:
                product_list_active_num = row[0]
        except:
            INFO("1Error: unable to fetch data")

        cursor_product_list_proer = db.cursor()
        product_list_sql_proer = "SELECT count(id) as display_num FROM test_kylin_web.product_list_for_proer;"
        try:
            # 执行SQL语句
            cursor_product_list_proer.execute(product_list_sql_proer)
            # 获取所有记录列表
            product_list_result_proer = cursor_product_list_proer.fetchall()
            for row in product_list_result_proer:
                product_list_active_num_proer = row[0]
        except:
            INFO("2Error: unable to fetch data")
        CHECK_POINT("核对超级管理员查看产品列表数量与产品管理员查看产品列表数量是否一致",
                    product_list_active_num_proer == product_list_active_num)

        STEP(3,"从普通用户的产品列表中挑选10条与产品管理员产品列表核对详细的产品信息")
        db = connect()
        INFO('数据库已连接')
        cursor_product_list_detail = db.cursor()
        product_list_detail_sql = "SELECT product_name,version,creater,create_time,update_time,product_function,introduction FROM test_kylin_web.product_list_for_user WHERE creater = '张三' OR creater = '张31';"

        try:
            # 执行SQL语句
            cursor_product_list_detail.execute(product_list_detail_sql)
            # 获取所有记录列表
            product_list_detail_result = cursor_product_list_detail.fetchall()
            require_list = list(list(items) for items in list(product_list_detail_result))
            INFO(require_list)
        except:
            INFO("3Error: unable to fetch data")

        # from productor
        cursor_product_list_detail_productor = db.cursor()
        product_list_detail_productor_sql = "SELECT product_name,version,creater,create_time,update_time,product_function,introduction FROM test_kylin_web.product_list_for_proer WHERE creater = '张三' OR creater = '张31';"
        try:
            # 执行SQL语句
            cursor_product_list_detail_productor.execute(product_list_detail_productor_sql)
            # 获取所有记录列表
            product_list_detail_productor_result = cursor_product_list_detail_productor.fetchall()
            require_list_productor = list(list(items) for items in list(product_list_detail_productor_result))
            # INFO(require_list_productor)
            CHECK_POINT("比较得到数据列表是否一致", sorted(require_list_productor) == sorted(require_list))
        except:
            INFO("2Error: unable to fetch data")

        db.close()